﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using ZH.Infrastructure.Dto.Request.Login;
using ZH.Infrastructure.Dto.Response.admin;
using ZH.Infrastructure.Dto.Response;
using ZH.Infrastructure.Tools;
using ZH.Service.Interface;
using ZH.Service.Instance;
using ZH.Infrastructure.Dto.Request.Tech;
using ZH.Infrastructure.Dto.Request.Yuyue;
using ZH.Infrastructure.EFCore.MySql;
using Mysqlx.Crud;
using ZH.Infrastructure.Dto.Response.Me;

namespace ZH.Api.Admin.Controllers.Mobile
{
    /// <summary>
    /// 移动端"我的"页
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(Roles = "Mobile")]
    public class MeController : Controller
    {
        public readonly I_Mobile_Service _i_mobile_Service;
        public readonly I_Me_Service _i_Me_Service;


        public MeController(I_Mobile_Service mobile_Service, I_Me_Service i_Me_Service)
        {
            _i_mobile_Service = mobile_Service;
            _i_Me_Service = i_Me_Service;
        }

        /// <summary>
        /// 获取服务收藏列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_FWcollect(string? uid)
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Me_Service.Get_FWcollect(user, uid);
            return Ok(result);
        }



        /// <summary>
        /// 新增服务收藏
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Roles = "Mobile")]
        public async Task<IActionResult> Add_FWcollect(Me_Response_Dto dto)
        {
            var code =Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Me_Service.Add_FWcollect(dto, user.id);
            return Ok(result);
        }


        /// <summary>
        /// 删除收藏
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Roles = "Mobile")]
        public async Task<IActionResult> Del_FWcollect(Me_Response_Dto dto)
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Me_Service.Del_FWcollect(dto, user.id);
            return Ok(result);
        }

        /// <summary>
        /// 判断是否收藏
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [Authorize(Roles = "Mobile")]
        [HttpPost]
        public async Task<IActionResult> Get_sc (ls s)
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Me_Service.Get_sc(s.Id, user.id);
            return Ok(result);
        }

        public class ls
        {
            public string? Id { get; set; }  // 对应前端传递的id
        }


    }
}
